library SitrepCommand initializer init requires LegacySystem

	globals
		private boolean sitrepEnabled = false
	endglobals
	
	private function SitrepEnabled takes nothing returns boolean
		return sitrepEnabled
	endfunction
	
	function EnableSitrep takes nothing returns nothing
		set sitrepEnabled = true
	endfunction
	
	private function SitrepCommand takes nothing returns nothing
		local string s = SubString(GetEventPlayerChatString(),8,StringLength(GetEventPlayerChatString()))
		local integer id = S2I(s)
		local integer i = 1
		if id==1 then
			call MBSet(udg_SquadStatus,3,3,"Experience")
			set udg_SITREP=1
		elseif id==2 then
			call MBSet(udg_SquadStatus,3,3,"Kills")
			set udg_SITREP=2
		elseif id==3 then
			call MBSet(udg_SquadStatus,3,3,"Movespeed")
			set udg_SITREP=3
		elseif StringLength(s)<36 then
			call MultiboardSetTitleText(udg_SquadStatus,s)
		endif
		loop
			exitwhen i>udg_InitialPlayers
			if udg_SITREP==1 then //Experience
				call MBSet( udg_SquadStatus,3,i+3,I2S(R2I(udg_Experience[udg_Sorted[i]])))
			elseif udg_SITREP==2 then //Kills
				call MBSet( udg_SquadStatus,3,i+3,I2S(GetPlayerScore(ConvertedPlayer(udg_Sorted[i]),PLAYER_SCORE_UNITS_KILLED)))
			else //ms
				call MBSet( udg_SquadStatus,3,i+3,I2S(R2I(GetUnitMoveSpeed(udg_Hero[udg_Sorted[i]]))))
			endif
			set i=i+1
		endloop
	endfunction

	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger()
		call TriggerRegisterPlayerChatEvent(t,Player(0),"-sitrep",false)
		call TriggerRegisterPlayerChatEvent(t,Player(5),"-sitrep",false)
		call TriggerAddCondition(t, Condition(function SitrepEnabled))
		call TriggerAddAction(t, function SitrepCommand)
	endfunction
endlibrary